package com.jdk.mode.struct;

/**
 * @author jukg
 * @date 2023/08/25 17:25
 * @description 桥接模式 两个不同维度为事物通过一方持有另一方的方式实现联系
 */
public class Bridge {

    public static void main(String[] args) {
        Phone p1 = new XiaoMi(new XiaomiAppStore());
        p1.start();
        p1 = new Huawei(new HuaweiAppStore());
        p1.start();
    }
}


interface AppStore{
    void download();
}

class XiaomiAppStore implements AppStore{

    @Override
    public void download() {
        System.out.println("小米应用商城");
    }
}
class HuaweiAppStore implements AppStore{

    @Override
    public void download() {
        System.out.println("华为应用商城");
    }
}


abstract class Phone{

    private AppStore appStore;

    public Phone(AppStore appStore) {
        this.appStore = appStore;
    }

    abstract void logo();

    void start(){
        logo();
        appStore.download();
    }
}

class XiaoMi extends Phone{

    public XiaoMi(AppStore appStore) {
        super(appStore);
    }

    @Override
    void logo() {
        System.out.println("小米手机欢迎你");
    }


}

class Huawei extends Phone{

    public Huawei(AppStore appStore) {
        super(appStore);
    }

    @Override
    void logo() {
        System.out.println("华为手机欢迎你");
    }
}
